<%@ page language="java" contentType="text/html; charset=windows-1255"
	pageEncoding="windows-1255"
	import="com.optimus.model.ShoppingCartBean,
	com.optimus.model.mapped.ProductBean,
	java.util.LinkedList,
	com.optimus.dao.ProductDAO,
	com.optimus.dao.ProductDAOImpl,
	com.optimus.utils.SpringUtils"%>
	
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="productBean" class="com.optimus.model.mapped.ProductBean" scope="request">
</jsp:useBean>
<jsp:useBean id="shoppingCartBean" class="com.optimus.model.ShoppingCartBean" scope="session">
</jsp:useBean>
<jsp:setProperty property="*" name="productBean" />


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="description" content="Smart Cart - a javascript shopping cart control for jQuery" />

<!--<script type="text/javascript" src="js/ShoppingCartJS/jquery-1.3.2.min.js"></script> -->
<script type="text/javascript" src="js/ShoppingCartJS/jquery-ui-1.7.2.custom.min.js"></script>
<script type="text/javascript" src="js/ShoppingCartJS/jquery.scrollTo-min.js"></script>
<script type="text/javascript" src="js/ShoppingCartJS/SmartCart.js"></script>

<script type="text/javascript">

		$(document).ready(function() {
		  // call the cart function
			$("#sc_cart").smartCart();
		}); 
	</script>
<link rel="stylesheet" type="text/css" href="css/ShoppingCartCSS/style_smartcart.css" />
</head>
	<body>
	<%
		if (request.getParameter("id") != null)
		{
			ProductDAO productDAO = (ProductDAO) SpringUtils.getBean("productDAO");
			ProductBean product = productDAO.selectEntityFromDbById(Integer.valueOf(request
					.getParameter("id")));
			ShoppingCartBean shoppingCart = null;
			if ((shoppingCart = (ShoppingCartBean) session.getAttribute("shoppingCart")) != null)
			{
				shoppingCart = (ShoppingCartBean) session.getAttribute("shoppingCart");
			}
			else
			{
				shoppingCart = new ShoppingCartBean();
				shoppingCart.setProductsList(new LinkedList<ProductBean>());
				shoppingCart.setTotalPrice(0.0);
			}
			int quantity = 1;
			if (request.getParameter("prod_qty") != null)
			{
				quantity = Integer.valueOf(request.getParameter("prod_qty"));
				quantity = quantity > 0 ? quantity : 1;
				shoppingCart.addProductToCart(product, quantity);
				session.removeAttribute("shoppingCart");
				session.setAttribute("shoppingCart", shoppingCart);
			}
			
			//productBean = product;%>
			<jsp:setProperty property="id" name="productBean" value="<%=product.getId()%>"/>
			<jsp:setProperty property="name" name="productBean" value="<%=product.getName()%>"/>
			<jsp:setProperty property="price" name="productBean" value="<%=product.getPrice()%>"/>
			<jsp:setProperty property="picturePath" name="productBean" value="<%=product.getPicturePath()%>"/>
			<jsp:setProperty property="categoryId" name="productBean" value="<%=product.getCategoryId()%>"/>
			<jsp:setProperty property="description" name="productBean" value="<%=product.getDescription()%>"/>
	<%
		}
	%>
	
	<!-- Product list HTML -->
	<div id="sc_productlist" class="scProductList">
		<div class="scProductListItem">
			<table border="0" cellpadding="2" cellspacing="2">
				<tr>
					<td rowspan="3"><img width="100px"
						src="<jsp:getProperty property="picturePath" name="productBean"/>" />
					</td>
					<td><strong><span id="prod_name100"><jsp:getProperty
						property="name" name="productBean" /></span> </strong></td>
				</tr>
				<tr>
					<td><label>Price:</label> $<span id="prod_price100"><jsp:getProperty
						property="price" name="productBean" /></span></td>
				</tr>
				<tr>
					<td>
					<form action="productPage.jsp" method="get"><label>Quantity:</label>
					<input name="prod_qty" class="scText" id="prod_qty100" value="1"
						size="3" type="text"> <span>&nbsp;&nbsp;</span> <input
						type="hidden" name="id"
						value="<jsp:getProperty property="id" name="productBean"/>">
					<input type="image" src="images/addToCart.jpg" /></form>
					</td>
				</tr>
				<tr>
					<td><label>Description: <br />
					<jsp:getProperty property="description" name="productBean" /> </label></td>
				</tr>
			</table>
		</div>
		<br/>
		You can <a href="http://twitter.com/share" class="twitter-share-button" data-count="none" data-via="ZivLevy1">Tweet</a>
		<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
		about this product!<br/>
		<script src="http://widgets.twimg.com/j/2/widget.js"></script>
		<script>
		new TWTR.Widget({
		  version: 2,
		  type: 'search',
		  search: '<%=productBean.getName()%>',
		  interval: 6000,
		  title: 'See what other people think about this product',
		  subject: '<%=productBean.getName()%>',
		  width: 350,
		  height: 300,
		  theme: {
		    shell: {
		      background: '#222729',
		      color: '#ffffff'
		    },
		    tweets: {
		      background: '#ffffff',
		      color: '#444444',
		      links: '#1985b5'
		    }
		  },
		  features: {
		    scrollbar: false,
		    loop: true,
		    live: true,
		    hashtags: true,
		    timestamp: true,
		    avatars: true,
		    toptweets: true,
		    behavior: 'default'
		  }
		}).render().start();
		</script>
		Or...
		<br/>
		<fb:comments width="350"></fb:comments>
	</div>
	<!-- End Product list HTML -->
		<div id="fb-root" style="position: fixed;"></div>
		<script>
		  window.fbAsyncInit = function() {
		    FB.init({appId: 'your app id', status: true, cookie: true,
		             xfbml: true});
		  };
		  (function() {
		    var e = document.createElement('script'); e.async = true;
		    e.src = document.location.protocol +
		      '//connect.facebook.net/en_US/all.js';
		    document.getElementById('fb-root').appendChild(e);
		  }());
		</script>
	</body>
	<%@ include file="footer.jsp"%>
</html>
